<!doctype html>
<html>
<?php
	//setcookie("qrcode", "", time()-3600);
	if($_GET['qrcode']!=''){
		setcookie('qrcode', $_GET['qrcode'],time() + 86400);
		$_COOKIE['qrcode']=$_GET['qrcode'];
	}
	require_once('inc/weixiconfig.php');
	require_once('globals.php');
?>
<head>
<meta charset="UTF-8">
<meta content="initial-scale=1.0,user-scalable=no,width=device-width" name="viewport" />
<meta content="telephone=no" name="format-detection" />
<title>专家预约</title>
<link href="static/css/main.css" rel="stylesheet" type="text/css" />
<link href="static/css/wx.css" rel="stylesheet" type="text/css" />
<link href="https://cdn.bootcss.com/sweetalert/1.1.3/sweetalert.min.css" rel="stylesheet">
<link href="https://cdn.bootcss.com/jquery-weui/1.0.1/css/jquery-weui.css" rel="stylesheet">
</head>
<style media="screen">
	.quane,.yue{
		display: block;
		text-indent: 60px;
		font-size: 12px;
		color: #000;
		line-height: 25px;
	}
	.quane .num{
		height:20px;
		width:55px;
		font-size:12px;
		text-align:center;
		margin-left: -10px;
	}
	.xinxi{
		text-align: center;
	    color: #5cb;
	    border-bottom: solid 1px #5cb;
	    line-height: 30px;
	    margin: 0 15px;
		font-size: 13px;
		font-weight: bold;
	}
	#bbb{
		position: relative;
	}
	#bbb button{
		position: absolute;
		right: 10px;
		top: 10px;
		background: #999;
		text-align: center;
		color: #333;
		padding: 0px 10px;
		height: 30px;
		line-height: 30px;
		border: none;
		outline: none;
		font-size: 12px;
	}
</style>
<body>
	<form>
		<div class="contactinfo orderpage clearfix">
			<div id="procon"></div>
			<script type="text/html" id="proconTemp">
				<div class="userinfo">
					<div class="userhead">
						<img src="{{data.image}}" alt="">
					</div>
					<div class="infobox">
						<span class="name">{{data.name}}</span>
						<span>从业时间：{{data.work_begin_time}}</span>
						<span>每次服务时间:{{data.serve_period}}分钟</span>
					</div>
				</div>
				<h2 class="jianjie">专家简介</h2>
				<div class="content">
					<div class="con">
						{{data.expert_intro}}
					</div>
					<div class="tipb">展开</div>
				</div>
	        </script>
			<h2 class="xinxi">预约信息</h2>
			<ul style="padding-bottom:0px">
				<li class="parentname"><span class="logo logo1" style="border-bottom:0px;"></span><span>您的姓名：<input class="per_name" type="text" name="parentname" value="" /></span></li>
				<li class="time"><span class="logo logo3" style="border-bottom:0px;"></span><span>您想预约的时间：<input style="width:50%" type="text" id='datetime-picker' placeholder="2006-07-02 08:09:04"/></span></li>
				<li class="parenttel" id="bbb">
					<span class="logo logo2" style="border-bottom:0px;"></span>
					<span>
						您的电话：<input class="per_phone" type="text" name="parenttel" value="" maxlength="11" />
						<button type="button" name="button" class="captch">获取验证码</button>
					</span>
				</li>
				<li class="parentname" id="capli">
					<span>
						验证码：<input type="text" name="parentname" value="" id="captcher" class="par_num" style="width:40%;"/>
					</span>
				</li>
				<li class="comment clearfix">
					<span>
						备注：<textarea name="comment" cols="30" rows="4" placeholder="备注可填写想预约时间及其他情况说明。"></textarea>
					</span>
				</li>
			</ul>
		</div>

		<div class="clearfix" id="introl">&nbsp;</div>
		<script type="text/html" id="introlTemp">
			<span class="yue" style="display:none" >预约费用:<%=data.subsist%>元</span>
			<span class="quane">预约费用：<%=data.subsist%>元/次&nbsp&nbspx&nbsp&nbsp&nbsp
				<select id="num" name="num" class="num">
					<option value="1" selected="selected">1次</option>
					<option value="2">2次</option>
					<option value="3">3次</option>
					<option value="4">4次</option>
					<option value="5">5次</option>
					<option value="6">6次</option>
					<option value="7">7次</option>
					<option value="8">8次</option>
					<option value="9">9次</option>
					<option value="10">10次</option>
					<option value="11">11次</option>
					<option value="12">12次</option>
				</select>
			</span>
			<div class="order-introduce" id="cons" style="margin-top:20px">
				<h2>预约说明</h2>
				<p class="tip-alert-info"  style="margin-bottom:65px;margin-top:15px;">
					预约须知：</br>
					客服热线：0571-28284036转168。</br>
					预约成功后，我们工作人员将在24小时内与您联系，并确定预约时间、地点等。</br>
					隐私安全：我们将会对您的所有信息进行保密。</br>
					若变更预约：若因为不可抗力需要变更/取消已协商好的咨询预约，请务必提前24小时联络工作人员，否则咨询将如期开始。</br>
					爽约/迟到：若没有提前24小时告知情况，爽约/迟到20分钟以上，则默认这次咨询已经完成。其他特殊情况，需与我公司协商处理。</br>
					退款说明：48小时以上取消预约的我们将无条件全额退款；小于48小时大于24小时内取消的，平台将收取20%的违约费；小于24（含）小时，全额不退款。</br>
				</p>
			</div>
			<div class="bottombar"><span>支付款项：<b id="howmuch"></b></span><input type="button" id="submitbt" value="确定预约" class="submitbotton" /></div>
		</script>
	</form>

</body>
<script src="http://cdn.bootcss.com/jquery/3.2.1/jquery.js"></script>
<script src="http://cdn.bootcss.com/sweetalert/1.1.3/sweetalert.min.js"></script>
<script src="js/aui-art-template-a880d14/lib/template-web.js" charset="utf-8"></script>
<script src="https://cdn.bootcss.com/jquery-weui/1.0.1/js/jquery-weui.js"></script>

<?php
$wxjs=1;
$class_info = $db->get('tb_class', '*', array('type'=>3,'tbid'=>$_GET['id'],'order'=>'tbid desc'));
$title='【屋童树的专家】'.$class_info['name'];
$desc=strip_tags($class_info['introduction']);
$link='http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$imagesurl='http://'.$_SERVER['HTTP_HOST'].'/static/img/sharelogo.jpg';
require_once('include.php');
?>
<script type="text/javascript">
$().ready(function(){
	function getParameter(){
		var url = location.search;
		var parameter = new Object();
		if(url.indexOf('?') != -1){
			var str = url.substr(1);
			strs = str.split('&');
			for(var i = 0; i < strs.length; i++){
				parameter[strs[i].split('=')[0]] = strs[i].split('=')[1];
			}
		}
		return parameter;
	}
	var time1 = nowtime();
	var flagg = true;
	var dataarr;
	var parmate = getParameter();
	var qrcode = parmate['qrcode'];
	$('#datetime-picker').attr('placeholder',time1)
	// 手机号是否验证
	$.ajax({
		type : "GET",
		async:false,
		url: 'http://www.familyandtree.com/getcontent.php?ac=check_mobile',
		dataType : "json",
		success : function(data){
			if (data.status == 2) {
				$('#bbb button').hide();
				$('#capli').hide();
			}else {
				$('#bbb button').show();
				$('#capli').show();
				flagg = false;
			}
		},
		error:function(data){
			swal({
				button: false,
				title: data.error,
			});
		}
	});

	// 获取验证码
	$('.captch').click(function(){
		gettime();
		$.ajax({
			type : "POST",
			async:false,
			url: 'http://www.familyandtree.com/getcontent.php?ac=mobile_send',
			data:{
				mobile:$('.per_phone').val()
			},
			dataType : "json",
			success : function(data){
				if (data.error != '') {
					swal({
						button: false,
						title: data.error,
					});
					$('.captch').attr("disabled",true)
					return false;
				}else {

				}
			},
			error:function(data){
				swal({
					button: false,
					title: data.error,
				});
			}
		});
	})
	//获取URL参数 By Jefi
	function GetQueryString(name){
		 var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
		 var r = window.location.search.substr(1).match(reg);
		 if(r!=null)return  unescape(r[2]); return null;
	}

	var sex,tbid=GetQueryString("id");

	// 专家详情
	$.ajax({
		type : "GET",
		async:false,
		url: 'http://www.familyandtree.com/getcontent.php?ac=class_info',
		data:{
			type:3,
			tbid
		},
		dataType : "json",
		success : function(data){
			if (data.error != '') {
				swal({
					button: false,
					title: data.error,
				});
				return false;
			}else {
				tbid = data.data.tbid;
				template.defaults.escape=false;
				$('#introl').append(template('introlTemp',data));
				$('#procon').append(template('proconTemp',data));
				//计算订单总价 By Jefi
				function TotalPrice(){
					var howmuch = data.data.subsist * $("#num").val();
					$("#howmuch").text("¥ "+ howmuch);
				}
				TotalPrice();
				$("#num").change(function(){
					TotalPrice();
				});
			}
		},
		error:function(data){
			swal({
				button: false,
				title: data.error,
			});
		}
	});

	$('.tipb').click(function() {
		$('.con').toggleClass('sliderdown')
		if ($('.con').hasClass('sliderdown')) {
			$(this).text('收起')
		}else {
			$(this).text('展开')
		}
	})
	$('#submitbt').click(function(){
		var wtime = $('#datetime-picker').val();
		var writeunixtime =  wtime.replace(new RegExp("-","gm"),"/");
		var writetime = new Date(writeunixtime).getTime();

		var nowtime = new Date();
		var nowunixtime = new Date(nowtime).getTime();


		if (writetime - nowunixtime < 86400000) {
			swal({
				button: false,
				title: '24小时后才能预约哦~',
			});
			return false;
		}
		if ($('#datetime-picker').val() == '') {
			swal({
				button: false,
				title: '请选择预约时间~',
			});
			return false;
		}

		if ($('#kidage').val() == '' ||  $('.per_phone').val() == '' || $('.per_name').val() == '') {
			swal({
				button: false,
				title: '请完善个人信息',
			});
			return false;
		}

		if(!(/^1(3|4|5|7|8)\d{9}$/.test($('.per_phone').val()))){
			swal({
				button: false,
				title: '请输入正确的手机号~',
			});
			return false;
		}
		if (flagg == false) {
			dataarr = {
				mark:3,
				type:3,
				is_test:1,
				p_phone:$('.per_phone').val(),
				p_name:$('.per_name').val(),
				remark:$('textarea').val(),
				num:$("#num").val(),
				class_id:tbid,
				reserve_time:$('#datetime-picker').val(),
				captcha:$('#captcher').val(),
				qrcode:<?php echo empty($_COOKIE['qrcode'])?0:$_COOKIE['qrcode'];?>
			};
			if ($('#captcher').val() == '') {
				swal({
					button: false,
					title: '请填写验证码',
				});
				return false;
			}
		}else {
			dataarr = {
				mark:3,
				type:3,
				is_test:1,
				p_phone:$('.per_phone').val(),
				p_name:$('.per_name').val(),
				remark:$('textarea').val(),
				num:$("#num").val(),
				class_id:tbid,
				reserve_time:$('#datetime-picker').val(),
				qrcode:<?php echo empty($_COOKIE['qrcode'])?0:$_COOKIE['qrcode'];?>
			}
		}
		var qrcode='<?php echo empty($_COOKIE['qrcode'])?0:$_COOKIE['qrcode'];?>';


		$.ajax({
			type : "POST",
			async:false,
			url: 'http://www.familyandtree.com/getcontent.php?ac=gen_order_pro',
			data:dataarr,
			dataType : "json",
			success : function(data){
				if (data.error != '') {
					swal({
						button: false,
						title: data.error,
					});
					return false;
				}else {
					getpaydetail(data.order_no);
				}
			},
			error:function(data){
				swal({
					button: false,
					title: data.error,
				});
			}
		});
	})
})


	function getpaydetail(ordernumber){
		$.ajax({
			type : "POST",
			async:false,
			url: 'http://www.familyandtree.com/getcontent.php?ac=trade_pay',
			data:{
				ordernumber:ordernumber
			},
			dataType : "json",
			success : function(data){
				WeixinJSBridge.invoke(
					'getBrandWCPayRequest', {
						"appId" : "wx58c39a575f4eec96",     //公众号名称，由商户传入
						"timeStamp": data.data.timestamp,         //时间戳，自1970年以来的秒数
						"nonceStr" : data.data.noncestr, //随机串
						"package" : "prepay_id="+data.data.prepay_id,
						"signType" : "MD5",         //微信签名。方式：
						"paySign" : data.data.sign //微信签名
					},
					function(res){
						if(res.err_msg == "get_brand_wcpay_request:ok" ) {
							window.location.href='order_list.php'
						}else if(res.err_msg == "get_brand_wcpay_request:cancel" ) {
							swal({
								button: false,
								title: '交易已取消~',
							});
						}else{
							swal({
								button: false,
								title: '支付失败！',
							});
						}     // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。
					}
				);
			},
			error:function(data){
				swal({
					button: false,
					title: data.error,
				});
			}
		});
	}
	$("#datetime-picker").datetimePicker();

	function isPhoneNo(phone) {
		var pattern = /^1[34578]\d{9}$/;
		return pattern.test(phone);
 	}

	function gettime(){
		var time = 60;
		var t = setInterval(function(){
			$('.captch').text(time + '秒后重新获取')
			$('.captch').attr("disabled",true)
			time--;
			if (time == '0') {
				$('.captch').text('重新获取')
				$('.captch').attr("disabled",false)
				clearInterval(t);
			}
		},1000);
	}
	function nowtime(){//将当前时间转换成yyyymmdd格式
	    var mydate = new Date();
	    var str =  mydate.getFullYear()+'-';
	    var mm = mydate.getMonth()+1
	    if(mydate.getMonth()>9){
	     str += mm+'-';
	    }
	    else{
	     str += "0" + mm;
	    }
	    if(mydate.getDate()>9){
	     str += mydate.getDate();
	    }
	    else{
	     str += "0" + mydate.getDate();
	    }
	    return str;
  }
	function getParameter(){
			var url = location.search;
			var parameter = new Object();
			if(url.indexOf('?') != -1){
				var str = url.substr(1);
				strs = str.split('&');
				for(var i = 0; i < strs.length; i++){
					parameter[strs[i].split('=')[0]] = unescape(strs[i].split('=')[1]);
				}
			}
			return parameter;
		}
</script>
</html>
